"use strict";
import * as types from './types'
export const mutations = {
  [types.SET_LIST] (state, list_data) {
    for (let index in list_data) {
      let item = list_data[index];
      item.field_mai_img = '/api' + item.field_mai_img;
      if (item.field_mai_lv_re == ' ' || item.field_mai_lv_re == '') {
        item.field_mai_lv_re = '-';
      }
      let reg_html = /<\/?[^>]*>/g;
      item.field_mai_lv_expert = item.field_mai_lv_expert.replace(reg_html, '');
      item.field_mai_lv_master = item.field_mai_lv_master.replace(reg_html, '');
      item.field_mai_lv_re = item.field_mai_lv_re.replace(reg_html, '');

      let reg_kuohao =  /\(.*\)/;
      item.field_mai_lv_expert = item.field_mai_lv_expert.replace(reg_kuohao, '');
      item.field_mai_lv_master = item.field_mai_lv_master.replace(reg_kuohao, '');
      item.field_mai_lv_re = item.field_mai_lv_re.replace(reg_kuohao, '');

      // let reg_field_collection = /\/[0-9]{1,3}/g;
      // item.field_mai_score = item.field_mai_score.match(reg_field_collection);
      //item.field_mai_score = item.field_mai_score[0].replace('\/', '');
      state.track_list.push(item);
    }
  },
  [types.CLEAR_LIST] (state) {
    state.track_list.splice(0, state.track_list.length);
  },
  [types.ADD_PAGE] (state) {
    state.page += 1;
  },
  [types.CLEAR_PAGER] (state) {
    state.page = 0;
  },
  [types.SET_GENERA] (state, genera_id) {
    state.genera = genera_id;
  },
  [types.SET_SEARCH_LV] (state, lv) {
    state.search_lv = lv;
  },
  [types.SET_SEARCH_WORD] (state, key_word) {
    state.search_word = key_word;
  },
  [types.SHOW_LIST] (state, value) {
    state.show_list = value
  },
  [types.NO_MORE] (state, value) {
    state.no_more = value
  },
  [types.SET_DETAIL] (state, row_data) {
    state.track_detail[0].col1.title = row_data.title[0].value;
    if (row_data.field_mai_title_en[0]) {
      state.track_detail[0].col1.en_name = row_data.field_mai_title_en[0].value;
    }
    else {
      state.track_detail[0].col1.en_name = '';
    }

    let replact_api_reg = /http:\/\/.*?\//;
    state.track_detail[0].col1.src = row_data.field_mai_img[0].url.replace(replact_api_reg, '/api/');
    state.track_detail[0].col2 = row_data.field_mai_artist[0].value;

    if (row_data.field_mai_genera[0]) {
      let term_id = row_data.field_mai_genera[0].target_id;
      switch (term_id) {
        case types.TERM_POPS: {
          state.track_detail[1].col2 = 'POPS ＆ アニメ';
          break;
        }
        case types.TERM_NICO: {
          state.track_detail[1].col2 = 'niconico ＆ ボーカロイド';
          break;
        }
        case types.TERM_TOUHOU: {
          state.track_detail[1].col2 = '東方Project';
          break;
        }
        case types.TERM_SEGA: {
          state.track_detail[1].col2 = 'SEGA';
          break;
        }
        case types.TERM_GAME: {
          state.track_detail[1].col2 = 'ゲーム ＆ バラエティ';
          break;
        }
        case types.TERM_ORIGINAL: {
          state.track_detail[1].col2 = 'オリジナル＆ジョイポリス';
          break;
        }
      }
    }

    let data_reg = /20[0-9]{2}\/[0-9]{1,2}\/[0-9]{1,2}/;
    //let data_reg = /.*/g;
    //state.track_detail[2].col2 = row_data.field_mai_comment[0].value.match(data_reg);
    let track_append_time = new Date(Date.parse(row_data.field_mai_comment[0].value.match(data_reg))).getTime();

    let murasaki_append_time = '2016/12/15';
    let pink_plus_append_time = '2016/6/30';
    let pink_append_time = '2015/12/9';
    let orange_plus_append_time = '2015/3/19';
    let orange_append_time = '2014/9/18';
    let green_plus_append_time = '2014/2/26';
    let green_append_time = '2013/7/11';
    let maimai_plus_append_time = '2012/12/13';

    if (track_append_time >= new Date(Date.parse(murasaki_append_time)).getTime()) {
      state.track_detail[2].col2 = 'MURASAKi';
    }
    else if (track_append_time >= new Date(Date.parse(pink_plus_append_time)).getTime()) {
      state.track_detail[2].col2 = 'PiNK+';
    }
    else if (track_append_time >= new Date(Date.parse(pink_append_time)).getTime()) {
      state.track_detail[2].col2 = 'PiNK';
    }
    else if (track_append_time >= new Date(Date.parse(orange_plus_append_time)).getTime()) {
      state.track_detail[2].col2 = 'ORANGE+';
    }
    else if (track_append_time >= new Date(Date.parse(orange_append_time)).getTime()) {
      state.track_detail[2].col2 = 'ORANGE';
    }
    else if (track_append_time >= new Date(Date.parse(green_plus_append_time)).getTime()) {
      state.track_detail[2].col2 = 'GREEN+';
    }
    else if (track_append_time >= new Date(Date.parse(green_append_time)).getTime()) {
      state.track_detail[2].col2 = 'GREEN';
    }
    else if (track_append_time >= new Date(Date.parse(maimai_plus_append_time)).getTime()) {
      state.track_detail[2].col2 = 'MAIMAI PLUS';
    }
    else
    {
      state.track_detail[2].col2 = 'MAIMAI';
    }

    //state.track_detail[2].col2 = new Date(Date.parse(row_data.field_mai_comment[0].value.match(data_reg))).getTime();
    state.track_detail[3].col2 = row_data.field_mai_comment[0].value;
  },
  [types.SET_SCROLL] (state, value) {
    state.scrollTop = value;
  },
  [types.SET_DETAIL_HEIGHT] (state, value) {
    state.detail_height = value;
  },
  [types.SHOW_SEARCH] (state, value) {
    state.show_search = value;
    if (!value) {
      state.search_word = '';
    }
  },
  [types.SET_LV_DETAIL] (state, data) {
    state.track_score_data = [];
    state.track_score_data.push({
      type: '理论值',
      lv: data.field_mai_s_achi.map((item) => {
        return item.value;
      })
    });

    state.track_score_data.push({
      type: 'Break',
      lv: data.field_mai_s_break.map((item) => {
        return item.value;
      })
    });

    state.track_score_data.push({
      type: 'Hold',
      lv: data.field_mai_s_hold.map((item) => {
        return item.value;
      })
    });

    state.track_score_data.push({
      type: 'Slide',
      lv: data.field_mai_s_slide.map((item) => {
        return item.value;
      })
    });

    state.track_score_data.push({
      type: 'Tap',
      lv: data.field_mai_s_tap.map((item) => {
        return item.value;
      })
    });

    state.track_score_data.push({
      type: 'Total',
      lv: data.field_mai_s_total.map((item) => {
        return item.value;
      })
    });
  }
};
